//
//  FSHomeEmailViewController.m
//  Trade
//
//  Created by 刘沿 on 16/4/15.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSHomeEmailViewController.h"

@interface FSHomeEmailViewController ()

//科室收件箱邮件个数
@property (weak, nonatomic) IBOutlet UILabel *publicReceiveEmail;
//科室发件箱邮件个数
//@property (weak, nonatomic) IBOutlet UILabel *publicSendEmail;
//个人收件箱邮件个数
@property (weak, nonatomic) IBOutlet UILabel *profileReceiveEmail;
////个人发件箱邮件个数
//@property (weak, nonatomic) IBOutlet UILabel *profileSendEmail;
//科室收件箱cell
@property (weak, nonatomic) IBOutlet UITableViewCell *publicReceiveCell;
//科室发件箱cell
@property (weak, nonatomic) IBOutlet UITableViewCell *publicSendCell;
//个人收件箱cell
@property (weak, nonatomic) IBOutlet UITableViewCell *profileReceiveCell;
//个人发件箱cell
@property (weak, nonatomic) IBOutlet UITableViewCell *profileSendCell;

@property(nonatomic,assign)NSInteger whetherMail;

@end

@implementation FSHomeEmailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setLayer:self.publicReceiveEmail];
//    [self setLayer:self.publicSendEmail];
    [self setLayer:self.profileReceiveEmail];
//    [self setLayer:self.profileSendEmail];
    self.publicReceiveEmail.hidden = YES;
    self.profileReceiveEmail.hidden = YES;
    
    [self loadData];
    [self setLeftItem];
}
- (void)setLeftItem{
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] init];
    
    leftItem.title = @"返回";
    
    self.navigationItem.backBarButtonItem = leftItem;
}

-(void)setLayer:(UILabel*)label{
    label.layer.cornerRadius = label.frame.size.width / 2;
    label.layer.masksToBounds = YES;
}

-(void)loadData{
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"userId":userId}];;
    [HttpTools requestWithURL:Kexchmain arrays:array method:KhomeMailwoiunu success:^(id JSON) {
        NSArray *tempArray  = JSON[@"data"];
        NSDictionary * dict = [tempArray firstObject];
        [self setSubViews:dict];
    } failure:^(NSError *error) {
        
    }];
}

-(void)setSubViews:(NSDictionary*)dict{
    if ([dict[@"ksmail"] integerValue] !=0) {
//科室收件箱邮件个数
        self.publicReceiveEmail.text = dict[@"ksmail"];
        self.publicReceiveEmail.hidden = NO;
    }
    
    if ([dict[@"mail"] integerValue] !=0) {
//个人收件箱邮件个数
        self.profileReceiveEmail.text = dict[@"mail"];
        self.profileReceiveEmail.hidden = NO;
    }
    
    self.whetherMail = [dict[@"whetherMail"] integerValue];
    if (self.whetherMail ==1) {
        self.publicReceiveCell.hidden = NO;
        self.publicSendCell.hidden = NO;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==0 || indexPath.row == 1) {
        if (self.whetherMail == 0) {
            return 0;
        }
    }
    return 86;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    switch (indexPath.row){
        case 0:{//科室收件箱
            FSInBoxViewController * inBoxVC  = (FSInBoxViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"InBoxViewVC"];
            inBoxVC.isKeShi = YES;
            [self.navigationController pushViewController:inBoxVC animated:YES];
            break;
        }
        case 1:{ //科室发件箱
            FSSendMessageViewController * sendVC  = (FSSendMessageViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"SendMessageVCID"];
            sendVC.isKeShi = YES;
            [self.navigationController pushViewController:sendVC animated:YES];
            break;
        }
        case 2:{ //个人收件箱
            FSInBoxViewController * inBoxVC  = (FSInBoxViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"InBoxVCID"];
            [self.navigationController pushViewController:inBoxVC animated:YES];
            break;
        }
        case 3:{ //个人发件箱
            FSSendMessageViewController * sendVC  = (FSSendMessageViewController*)[storyBoard instantiateViewControllerWithIdentifier:@"SendMessageVCID"];
            [self.navigationController pushViewController:sendVC animated:YES];
            break;
        }
        default:
            break;
    }
    
}

@end
